<template>
  <div class="row">
    <templates-picker
      v-if="!selectedWaTemplate"
      :inbox-id="inboxId"
      @onSelect="pickTemplate"
    />
    <template-parser
      v-else
      :template="selectedWaTemplate"
      @resetTemplate="onResetTemplate"
      @sendMessage="onSendMessage"
    />
  </div>
</template>

<script>
import TemplatesPicker from '@/components/widgets/conversation/WhatsappTemplates/TemplatesPicker.vue'
import TemplateParser from '@/components/widgets/conversation/WhatsappTemplates/TemplateParser.vue'
export default {
  components: {
    TemplatesPicker,
    TemplateParser,
  },
  props: {
    inboxId: {
      type: String,
      default: '',
    },
    show: {
      type: Boolean,
      default: true,
    },
  },
  data () {
    return {
      selectedWaTemplate: null,
    }
  },
  methods: {
    pickTemplate (template) {
      this.$emit('pickTemplate', true)
      this.selectedWaTemplate = template
    },
    onResetTemplate () {
      this.$emit('pickTemplate', false)
      this.selectedWaTemplate = null
    },
    onSendMessage (message) {
      this.$emit('on-send', message)
    },
    onClose () {
      this.$emit('cancel')
    },
  },
}
</script>

<style></style>
